var path = require('path')
var webpack = require('webpack')
var autoprefixer = require('autoprefixer')
var precss = require('precss')

var config = {
    devtool: 'source-map',
    entry: [
        './src/index'
    ],
    output: {
        path: path.join(__dirname, 'src/static/'),
        filename: 'bundle.js',
        publicPath: '/static/'
    },
    plugins: [
        new webpack.optimize.OccurenceOrderPlugin(),
    ],
    module: {
        /*
         http://babeljs.cn/docs/usage/babelrc/
         http://survivejs.com/webpack_react/webpack_and_react/
         可以不使用.babelrc,因为识别env环境变量需要配置系统，太不方便
        */
        loaders: [{
                test: /\.js$/,
                loader: 'babel',
                exclude: /node_modules/,
                query: {
                    cacheDirectory: true,
                    presets: ['react', 'es2015']
                },
                include: __dirname
            }, {
                test: /\.css$/,
                loader: "style-loader!css-loader!postcss-loader"
                    //loader: ExtractTextPlugin.extract("style-loader","css-loader!postcss-loader"),
                    //include: __dirname
            }, {
                test: /\.(png|jpg|gif)$/,
                loader: 'file-loader?name=img/[name].[ext]'
            }
            //{test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192'}
            //{test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192&name=images/[name].[ext]'}  
        ]
    },
    postcss: function() {
        return [autoprefixer, precss];
    }
}

module.exports = config;
